package learningThread.threadPool;

import java.util.concurrent.*;

/**
 * newFixedThreadPool 创建一个固定数量线程的线程池。
 * 对于newFixedThreadPool来说，它的最大线程池数量=核心线程池数量，
 * 此时任务队列也满了，将不能扩展创建新的线程来执行任务
 */
public class TestNewFixedThreadExcutorPool {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        ThreadPoolExecutor executorService1 = (ThreadPoolExecutor) executorService;
        for (int i = 0; i < 30; i++) {
            executorService.submit(() -> {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("当前线程核心线程数:"+executorService1.getCorePoolSize()
                        +"最大线程数:"+executorService1.getMaximumPoolSize()
                        +"线程存活时间:"+executorService1.getKeepAliveTime(TimeUnit.MILLISECONDS)
                        +"已完成的线程数:"+executorService1.getCompletedTaskCount()
                        +"存活的线程数为:"+executorService1.getActiveCount());
                System.out.println("当前线程池数量:"+executorService1.getPoolSize());
            });


        }








    }
}
